from test_driver import *
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
driver = ky_caps()
#注册

# driver.find_element(By.ID,'android:id/button2').click()
# sleep(1)
# driver.find_element(By.ID,'com.tal.kaoyan:id/tv_skip').click()
# sleep(2)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/login_register_text').click()
# driver.find_elements(By.CLASS_NAME,'android.widget.EditText')[0].send_keys('liumengdan111')
# sleep(2)
# driver.find_element(By.ID,'com.tal.kaoyan:id/activity_register_password_edittext').send_keys('lmd123456')
# sleep(2)
# driver.find_elements(By.CLASS_NAME,'android.widget.EditText')[2].send_keys('liumengdan111@163.com')
# sleep(2)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/activity_register_userheader').click()   #点击换头像
# sleep(1)
# driver.find_elements(By.CLASS_NAME, 'android.widget.ImageView')[1].click() #选择头像
# sleep(2)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/save').click()
# sleep(2)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/activity_register_register_btn').click()
# sleep(2)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/activity_perfectinfomation_time').click()
# sleep(2)
# driver.find_elements(By.CLASS_NAME, 'android.widget.TextView')[5].click()
# sleep(2)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/perfectinfomation_edit_school_name').click()
# sleep(1)
# driver.find_elements(By.CLASS_NAME, 'android.widget.TextView')[0].click()
# sleep(1)
# driver.find_elements(By.CLASS_NAME, 'android.widget.TextView')[0].click()
# sleep(1)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/activity_perfectinfomation_major').click()
# sleep(1)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/activity_marjorsubject_zhuanye').click()
# sleep(1)
# driver.find_elements(By.CLASS_NAME, 'android.widget.TextView')[5].click()
# sleep(1)
# driver.find_elements(By.CLASS_NAME, 'android.widget.TextView')[3].click()
# sleep(1)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/major_search_item_name').click()
# sleep(1)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/activity_perfectinfomation_goBtn').click()
# sleep(1)
# driver.find_element(By.ID, 'com.tal.kaoyan:id/task_no_task').click()
# sleep(1)
# driver.quit()

#登录
# ky_caps().find_element(By.ID, 'android:id/button2').click()
# ky_caps().find_element(By.ID, 'com.tal.kaoyan:id/tv_skip').click()
# ky_caps().find_element(By.ID, 'com.tal.kaoyan:id/login_email_edittext').send_keys('lmd123')
# ky_caps().find_element(By.ID, 'com.tal.kaoyan:id/login_password_edittext').send_keys('123456')
# ky_caps().find_element(By.ID, 'com.tal.kaoyan:id/login_login_btn').click()

# 点击取消
try:
    ele = driver.find_element(By.ID, 'android:id/button2')
except Exception as e:
    print('no button')
else:
    ele.click()
# 点击跳过
try:
    ele = driver.find_element(By.ID, 'com.tal.kaoyan:id/tv_skip')
except Exception as e:
    print('not button')
else:
    ele.click()

driver.find_element(By.ID, 'com.tal.kaoyan:id/login_email_edittext').send_keys('liumengdan333')
driver.find_element(By.ID, 'com.tal.kaoyan:id/login_password_edittext').send_keys('123456')
driver.find_element(By.ID, 'com.tal.kaoyan:id/login_login_btn').click()
#toast定位
toast_loc = (By.XPATH, '//*[@text="验证失败次数过多，请 15 分钟后再试"]')
ele_toast = WebDriverWait(driver, 30, 0.5).until(EC.presence_of_element_located(toast_loc))
print(ele_toast.text)
driver.quit()




